<?
        require_once '../inc/functions.php';
        require_once dirname(__FILE__) . '/data.php';
        require_once dirname(__FILE__) . '/../Users/data.php';
        require_once dirname(__FILE__) . '/../Lookups/data.php';
        $section='Users';
        
        if(isset($_REQUEST['Address']))
        {
                $rs = $_REQUEST;
                $errors = Validate($rs);
                if(!$errors)
                        $errors = Save($rs);
                if(!$errors)
                {
                        header("Location: index.php?new_id=$rs[id]");
                }
        }
        elseif(isset($_REQUEST['id']))
                $rs = Get($_REQUEST['id']);
        else
                $rs = Blank();

	
                
        $resultsUesrs = Users::GetAll();
        $resultsLookups = Lookups::GetAll();
?>

<!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Users</title>
        <style type="text/css">
                        .error { color: red; }
                        input.error {
                                border: 1px solid red;
                                background: #FEE;
                        }
                </style>
    </head>
    
    <body>
    
                <? include("../inc/tabs.php"); ?>
        <div id="container">
        <h1>Edit an Address</h1>
        <ul class="error">
                <? foreach($errors as $field => $error){ ?>
                <li><?=$field?>: <?=$error?></li>
            <? } ?>
        </ul>
        
        <form method="post" action="">
                <label>id:</label>
                <?=$rs['id']?>
            <br />
                <label for="created_at">created_at</label>
                <input  type="datetime"
                        name="created_at" id="created_at"
                    value="<?=$rs['created_at']?>"
                    class="<?=isset($errors['created_at']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['created_at']?></span>
            <br />




                <label for="updated_at">updated_at</label>
                <input  type="datetime"
                        name="updated_at" id="updated_at"
                    value="<?=$rs['updated_at']?>"
                    class="<?=isset($errors['updated_at']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['updated_at']?></span>
            <br />




                <label for="User_id">User:</label>
            <select size="1" name="User_id" id="User_id"
                    class="<?=isset($errors['User_id']) ? 'error' : '' ?>" >
                <? while($rsUsers = $resultsUesrs->fetch_assoc()){ ?>
                    <option value="<?=$rsUsers['id']?>" 
                                <? if($rsUsers['id'] == $rs['User_id']){ ?>
                                selected="selected"
                            <? } ?>
                    >
              <?=$rsUsers['FirstName']?> <?=$rsUsers['LastName']?>
                     </option>
                                <? } ?>
            </select>
            <span class="error"><?=$errors['User_id']?></span>
            <br />

	
                <label for="Address">Address</label>
                <input  type="text"
                        name="Address" id="Address"
                    value="<?=$rs['Address']?>"
                    class="<?=isset($errors['Address']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Address']?></span>
            <br />

	<label for="AppartmentNum">AppartmentNum</label>
                <input  type="text"
                        name="AppartmentNum" id="AppartmentNum"
                    value="<?=$rs['AppartmentNum']?>"
                    class="<?=isset($errors['AppartmentNum']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['AppartmentNum']?></span>
            <br />

	<label for="City">City</label>
                <input  type="text"
                        name="City" id="City"
                    value="<?=$rs['City']?>"
                    class="<?=isset($errors['City']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['City']?></span>
            <br />
	
<label for="State">State</label>
                <input  type="text"
                        name="State" id="State"
                    value="<?=$rs['State']?>"
                    class="<?=isset($errors['State']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['State']?></span>
            <br />
		
<label for="Zip">Zip</label>
                <input  type="text"
                        name="Zip" id="Zip"
                    value="<?=$rs['Zip']?>"
                    class="<?=isset($errors['Zip']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Zip']?></span>
            <br />
<label for="Country">Country</label>
                <input  type="text"
                        name="Country" id="Country"
                    value="<?=$rs['Country']?>"
                    class="<?=isset($errors['Country']) ? 'error' : '' ?>" />
            <span class="error"><?=$errors['Country']?></span>
            <br />
            <input type="submit" value="Save" />
        </form></div>
        </body>
</html>
